﻿using System;
using System.Collections;

namespace _1.求数据的素数因子
{
    class Program
    {

        static bool IsPrime(int num)
        {
            if (num == 2) return true;
            double sqrt_num = Math.Sqrt(num);
            for (int i = 2; i <= sqrt_num; ++i)
            {
                if (num % i == 0) return false;
            }
            return true;
        }

        static void Main(string[] args)
        {
            Console.WriteLine("请输入数据：");
            string num_str = Console.ReadLine();
            int num = Convert.ToInt32(num_str);

            double sqrt_num = Math.Sqrt(num);

            ArrayList PrimeFactor = new ArrayList();

            for(int i = 2; i <= sqrt_num; ++i)
            {
                if (num % i == 0)
                {
                    int factor1 = i, factor2 = num / i;
                    if (IsPrime(factor1)) PrimeFactor.Add(factor1);
                    if (factor1 == factor2) continue;
                    if (IsPrime(factor2)) PrimeFactor.Add(factor2);
                }
            }

            PrimeFactor.Sort();
            Console.Write("所输入的数据的素数因子为：");
            foreach (int i in PrimeFactor)
            {
                Console.Write(i + " ");
            }

        }
    }
}
